package org.cunamas.core.dao.impl;

import java.sql.Types;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.inject.Inject;
import javax.sql.DataSource;

import org.cunamas.core.bean.ServiciosAlimentariosBean;
import org.cunamas.core.dao.ServiciosAlimentariosSpDao;
import org.cunamas.core.dto.Filtros;
import org.cunamas.core.dto.mapper.ServiciosAlimentariosMapper;
import org.cunamas.web.util.CunamasConstants;
import org.springframework.jdbc.core.SqlParameter;
import org.springframework.jdbc.core.SqlReturnResultSet;
import org.springframework.jdbc.object.StoredProcedure;
import org.springframework.stereotype.Component;

@Component
public class ServiciosAlimentariosDaoProcedureImpl extends StoredProcedure implements ServiciosAlimentariosSpDao {

	public static final String SPROC_NAME = CunamasConstants.SP_INDICADOR_SERVICIOS_ALIMENTARIOS;
	
	public static final String V_CODPRG = "V_CODPRG";
	public static final String V_UBIGEO = "V_UBIGEO";
	public static final String V_SEDE = "V_GSEDE";
	public static final String V_CODCOM = "V_CODCOM";
	public static final String V_ANIO = "V_ANIO";
	public static final String V_TRIMESTRE = "V_TRIMESTRE";
	public static final String V_FORMATO = "V_FORMATO";
	public static final String V_SUPERVISOR = "V_SUPERVISOR";

	@Inject
	public ServiciosAlimentariosDaoProcedureImpl(DataSource dataSource){
		super(dataSource, SPROC_NAME);
		declareParameter(new SqlReturnResultSet("rs", new ServiciosAlimentariosMapper()));
		declareParameter(new SqlParameter(V_CODPRG, Types.VARCHAR));
		declareParameter(new SqlParameter(V_UBIGEO, Types.VARCHAR));
	    declareParameter(new SqlParameter(V_SEDE, Types.VARCHAR));
	    declareParameter(new SqlParameter(V_CODCOM, Types.VARCHAR));
	    declareParameter(new SqlParameter(V_ANIO, Types.VARCHAR));
	    declareParameter(new SqlParameter(V_TRIMESTRE, Types.TINYINT));
	    declareParameter(new SqlParameter(V_FORMATO, Types.TINYINT));
	    declareParameter(new SqlParameter(V_SUPERVISOR, Types.TINYINT));
	    
	    compile();
	}
	
	public List<ServiciosAlimentariosBean> retornaServiciosAlimentarios(
			Filtros filtros) {
		Map<String, Object> inputs = new HashMap<String, Object>();
		inputs.put(V_CODPRG, CunamasConstants.COD_PROG);
	    inputs.put(V_UBIGEO, filtros.getUbigeo());
	    inputs.put(V_SEDE, filtros.getSede());
	    inputs.put(V_CODCOM, filtros.getCom());
	    inputs.put(V_ANIO, filtros.getAnio());	
	    inputs.put(V_TRIMESTRE, filtros.getTrimestre());
	    inputs.put(V_FORMATO, filtros.getFormato());
	    inputs.put(V_SUPERVISOR, filtros.getSupervisor());
	    System.out.println("PARAMETROS"+inputs);
	    
	    Map output= super.execute(inputs);
		return (ArrayList<ServiciosAlimentariosBean>)output.get("rs");
	}
	
}
